odhcpd: remove OAF_STATIC
authorDavid Härdeman <[email protected]>
Sun, 23 Nov 2025 23:19:15 +0000 (00:19 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Sun, 30 Nov 2025 16:00:17 +0000 (17:00 +0100)
This flag does nothing more than document if lease_cfg is set in the
respective dhcpv[46]_lease structs.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/331
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv4.c
src/dhcpv6-ia.c
src/odhcpd.h
src/ubus.c

index c41c13d6896af5fe11b935e7f95b7ea0ed92b1ef..ab1a762d7c00029b9cb14ca405ca03258a6c50e0 100644 (file)
@@ -589,7 +589,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
 
                lease->flags &= ~OAF_BOUND;
 
-               if (!(lease->flags & OAF_STATIC) || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) {
+               if (!lease->lease_cfg || lease->lease_cfg->ipv4.s_addr != lease->ipv4.s_addr) {
                        memset(lease->hwaddr, 0, sizeof(lease->hwaddr));
                        lease->valid_until = now + 3600; /* Block address for 1h */
                } else {
@@ -603,9 +603,9 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                        return NULL;
 
                /* Old lease, but with an address that is out-of-scope? */
-               if (lease && ((lease->ipv4.s_addr & iface->dhcpv4_own_ip.netmask) !=
-                    (iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_own_ip.netmask)) &&
-                   !(lease->flags & OAF_STATIC)) {
+               if (lease && !lease->lease_cfg &&
+                   ((lease->ipv4.s_addr & iface->dhcpv4_own_ip.netmask) !=
+                    (iface->dhcpv4_start_ip.s_addr & iface->dhcpv4_own_ip.netmask))) {
                        /* Try to reassign to an address that is in-scope */
                        avl_delete(&iface->dhcpv4_leases, &lease->iface_avl);
                        lease->ipv4.s_addr = INADDR_ANY;
@@ -634,8 +634,6 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                        }
 
                        if (lease_cfg) {
-                               lease->flags |= OAF_STATIC;
-
                                if (lease_cfg->hostname) {
                                        lease->hostname = strdup(lease_cfg->hostname);
                                        lease->hostname_valid = true;
@@ -663,7 +661,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg req_msg, const uint8_t *re
                        break;
                }
 
-               if ((!(lease->flags & OAF_STATIC) || !lease->hostname) && req_hostname_len > 0) {
+               if (req_hostname_len > 0 && (!lease->lease_cfg || !lease->lease_cfg->hostname)) {
                        char *new_name = realloc(lease->hostname, req_hostname_len + 1);
                        if (new_name) {
                                lease->hostname = new_name;
index cc27e5b266de4b96e320373d18de411493fd855a..1b17cf72efcb50fa05571bdd419508e19a7414de 100644 (file)
@@ -1171,8 +1171,6 @@ proceed:
                                                        assigned = assign_na(iface, a);
 
                                                if (lease_cfg && assigned) {
-                                                       a->flags |= OAF_STATIC;
-
                                                        if (lease_cfg->hostname) {
                                                                a->hostname = strdup(lease_cfg->hostname);
                                                                a->hostname_valid = true;
@@ -1240,7 +1238,7 @@ proceed:
                                   ((hdr->msg_type == DHCPV6_MSG_SOLICIT && rapid_commit) ||
                                    hdr->msg_type == DHCPV6_MSG_REQUEST ||
                                    hdr->msg_type == DHCPV6_MSG_REBIND)) {
-                               if ((!(a->flags & OAF_STATIC) || !a->hostname) && hostname_len > 0) {
+                               if (hostname_len > 0 && (!a->lease_cfg || !a->lease_cfg->hostname)) {
                                        char *tmp = realloc(a->hostname, hostname_len + 1);
                                        if (tmp) {
                                                a->hostname = tmp;
@@ -1277,7 +1275,7 @@ proceed:
                        } else if ((a->flags & OAF_DHCPV6_NA) && hdr->msg_type == DHCPV6_MSG_DECLINE) {
                                a->flags &= ~OAF_BOUND;
 
-                               if (!(a->flags & OAF_STATIC) || a->lease_cfg->hostid != a->assigned_host_id) {
+                               if (!a->lease_cfg || a->lease_cfg->hostid != a->assigned_host_id) {
                                        memset(a->duid, 0, a->duid_len);
                                        a->valid_until = now + 3600; /* Block address for 1h */
                                } else
index d4b87cf9c669a7bd399f425316ca0675234611d8..d7a32bb414d3471b0482e1db9d39f2f7194c0831 100644 (file)
@@ -192,9 +192,8 @@ enum odhcpd_mode {
 enum odhcpd_assignment_flags {
        OAF_TENTATIVE           = (1 << 0),
        OAF_BOUND               = (1 << 1),
-       OAF_STATIC              = (1 << 2),
-       OAF_DHCPV6_NA           = (1 << 3),
-       OAF_DHCPV6_PD           = (1 << 4),
+       OAF_DHCPV6_NA           = (1 << 2),
+       OAF_DHCPV6_PD           = (1 << 3),
 };
 
 /* 2-byte type + 128-byte DUID, RFC8415, §11.1 */
index eebedf0389f8f2d03d78e1b1293e79101833c9b8..5cbd09d2fae268ea02bc37312cdef3a31f16aa97 100644 (file)
@@ -62,7 +62,7 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _o_unused struct ubus_
                        if (c->flags & OAF_BOUND)
                                blobmsg_add_string(&b, NULL, "bound");
 
-                       if (c->flags & OAF_STATIC)
+                       if (c->lease_cfg)
                                blobmsg_add_string(&b, NULL, "static");
 
                        if (!c->hostname_valid)
@@ -154,7 +154,7 @@ static int handle_dhcpv6_leases(_o_unused struct ubus_context *ctx, _o_unused st
                        if (a->flags & OAF_BOUND)
                                blobmsg_add_string(&b, NULL, "bound");
 
-                       if (a->flags & OAF_STATIC)
+                       if (a->lease_cfg)
                                blobmsg_add_string(&b, NULL, "static");
                        blobmsg_close_array(&b, m);